Non-breaking space

In computer-based text processing and digital typesetting, a non-breaking space or no-break space (NBSP) is a variant of the space character that prevents an automatic line break (line wrap) at its position. In certain formats (such as HTML), it also prevents the “collapsing” of multiple consecutive whitespace characters into a single space. The non-breaking space is also known as a hard space or fixed space. In Unicode, it is encoded at U+00A0   no-break space (HTML:    ).

Contents

Non-breaking behavior

Text-processing software typically assumes that an automatic line break may be inserted anywhere a space character occurs; a non-breaking space prevents this from happening (provided the software recognizes the character). For example, if the text “100 km” will not quite fit at the end of a line, the software may insert a line break between “100” and “km”. To avoid this undesirable behaviour, the editor may choose to use a non-breaking space between “100” and “km”. This guarantees that the text “100 km” will not be broken: if it does not fit at the end of a line it is moved in its entirety to the next line.

Use as non-collapsing white-space

A second common application of non-breaking spaces is in plain text file formats such as SGML, HTML, TeX, and LaTeX, which sometimes treat sequences of whitespace characters (space, newline, tab, form feed, etc.) as if they were a single white-space character. Such “collapsing” of white-space allows the author to neatly arrange the source text using line breaks, indentation and other forms of spacing without affecting the final typeset result.

In contrast, non-breaking spaces are not merged with neighboring whitespace characters, and can therefore be used by an author to insert additional visible space in the formatted text. For example, in HTML, non-breaking spaces may be used in conjunction with a fixed-width font to create tabular alignment (courier new font family used):

   Column 1  Column 2
   --------  --------
        1.2       2.3

(note that the use of the pre tag, the whitespace:pre CSS rule, or a table are alternative, if not better, ways to achieve the same result in HTML)

If ordinary spaces are used instead then the spaces are collapsed when the HTML is rendered and the layout is broken:

Column 1 Column 2
-------- --------
1.2 2.3

Non-breaking space can also be used to automatically change formatting in a document. This is useful for things like class plans and recipe files where the description of a cell or line may be different from the actual text or title. For instance "recipe for: SOURDOUGH" can be set up to change font, point size, color, etc., anywhere on the line. First type text using the first format, then change the formatting as desired, insert the hard space by using cntrl+shift+space bar (in Word). When the cursor touches the hard space the formatting will change automatically to the second format. The non-breaking space works well for template documents that are used multiple times, making them quicker and easier to fill in.

Encodings

Format Representation of non-breaking space
Unicode and ISO/IEC 10646 U+00A0   no-break space (HTML:    ). Can be encoded by UTF-8 as 0xC2 0xA0.
ISO/IEC 8859 0xA0
CP1252 (Windows default in most countries using Germanic or Romance languages) 0xA0
KOI8-R 0x9A
EBCDIC 0x41
CP437, CP850, CP866 0xFF
SGML and HTML (including Wikitext) Character entity reference:  
Numeric character references:   or  
TeX tilde (~)
ASCII Not available

Unicode defines several other non-break space characters that differ from the regular space in width:

Keyboard entry methods

It is rare for national or international standards on keyboard layouts to define an input method for the non-breaking space. An exception is the Finnish Multilingual Keyboard, accepted as the national standard SFS 5966 in 2008. According to the SFS setting, the non-breaking space can be entered with the key combination AltGr + Space.[1]

Typically, authors of keyboard drivers and application programs (e.g., word processors) have devised their own keyboard shortcuts for the non-breaking space. For example:

System/application Entry method
Mac OS Option+Space
X11 Compose, Space, Space
Emacs Ctrl+X 8 Space
Vim Ctrl+K N S
Windows (all applications) Alt+0160 or Alt+255 (on numeric keypad)
Microsoft Word, Dreamweaver,
OpenOffice.org (since 3.0)
Ctrl+Shift+Space
WordPerfect, OpenOffice.org (before 3.0), LyX Ctrl+Space, Ctrl+Shift+Space for recent OpenOffice (see LP)
GTK-based applications Ctrl+Shift+U 00A0
Mac Adobe InDesign Option+Command+X
Many office applications Insert → Symbol dialog box (Latin-1 subset, after ~)

See also

References

  1. ^ Kotoistus: Uusi näppäinasettelu = Status of the new Keyboard Layout. A bi-lingual (Finnish + English) presentation page collecting drafts of the Finnish Multilingual Keyboard. CSC – IT Center for Science Ltd. (Page updated 2006-12-28.)